package com.base.vistter.iframe.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.base.vistter.iframe.entity.InverterDevicesPowerMonth;
import com.base.vistter.iframe.entity.InverterDevicesPowerYear;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

@Mapper
public interface InverterDevicesPowerYearMapper extends BaseMapper<InverterDevicesPowerYear> {

    @Select({"<script>",
            "SELECT ${column},report_time FROM inverter_devices_power_year WHERE inverter_devices_id = #{devicesId} and is_delete = 0 and report_time BETWEEN #{startTime} AND #{endTime} order by report_time ASC",
    "</script>"})
    List<InverterDevicesPowerYear> statisticsDevicesYear(@Param("column") String column, @Param("devicesId") Integer devicesId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);

    @Select("SELECT ${column},report_time FROM inverter_devices_power_day WHERE inverter_devices_id = #{devicesId} and is_delete = 0 and report_time BETWEEN #{startTime} AND #{endTime} order by report_time ASC LIMIT 1")
    InverterDevicesPowerYear getTodayPower(@Param("column") String column, @Param("devicesId") Integer devicesId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);

    @Select({"<script>",
            "SELECT SUM(dp) AS dp, MAKEDATE(${year}, 1) + INTERVAL (MONTH(report_time) - 1) MONTH AS report_time ",
            " FROM inverter_devices_power_year ",
            " WHERE YEAR(report_time) = #{year} ",
            " <if test='stationId != null'> AND inverter_station_id = #{stationId} </if>",
            " GROUP BY MONTH(report_time) ",
            " ORDER BY report_time ",
            "</script>"})
    List<InverterDevicesPowerYear> statisticsYear(@Param("stationId") Integer stationId,@Param("year") Integer year);

}
